/*   1:    */ package org.intellij.plugins.relaxNG.references;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.util.Condition;
import com.intellij.patterns.PsiFilePattern;
import com.intellij.patterns.XmlPatterns;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
import com.intellij.util.NotNullFunction;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */ 
/*  23:    */ public class FileReferenceUtil
/*  24:    */ {
/*  25:    */   public static PsiReference[] restrict(FileReferenceSet paramFileReferenceSet, Condition<PsiFile> paramCondition)
/*  26:    */   {
/*  27: 40 */     return restrict(paramFileReferenceSet, paramCondition, null);
/*  28:    */   }
/*  29:    */   
/*  30:    */   public static PsiReference[] restrict(FileReferenceSet paramFileReferenceSet, Condition<PsiFile> paramCondition, final Boolean paramBoolean)
/*  31:    */   {
/*  32: 44 */     FileReference[] arrayOfFileReference = paramFileReferenceSet.getAllReferences();
/*  33:    */     
/*  34: 46 */     (PsiReference[])ContainerUtil.map2Array(arrayOfFileReference, PsiReference.class, new NotNullFunction()
/*  35:    */     {
/*  36:    */       @NotNull
/*  37:    */       public PsiReference fun(FileReference paramAnonymousFileReference)
/*  38:    */       {
/*  39: 50 */         void tmp16_13 = new FileReferenceUtil.MyFileReference(paramAnonymousFileReference, this.val$cond, paramBoolean);
/*  40: 50 */         if (tmp16_13 == null) {
/*  41: 50 */           throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/references/FileReferenceUtil$1", "fun" }));
/*  42:    */         }
/*  43: 50 */         return tmp16_13;
/*  44:    */       }
/*  45:    */     });
/*  46:    */   }
/*  47:    */   
/*  48:    */   public static Condition<PsiFile> byType(FileType paramFileType)
/*  49:    */   {
/*  50: 56 */     return new TypeCondition(paramFileType);
/*  51:    */   }
/*  52:    */   
/*  53:    */   public static Condition<PsiFile> byNamespace(String paramString)
/*  54:    */   {
/*  55: 60 */     return new PatternCondition(XmlPatterns.xmlFile().withRootTag(XmlPatterns.xmlTag().withNamespace(XmlPatterns.string().equalTo(paramString))));
/*  56:    */   }
/*  57:    */   
/*  58:    */   private static class TypeCondition
/*  59:    */     implements Condition<PsiFile>
/*  60:    */   {
/*  61:    */     private final FileType a;
/*  62:    */     
/*  63:    */     public TypeCondition(FileType paramFileType)
/*  64:    */     {
/*  65: 67 */       this.a = paramFileType;
/*  66:    */     }
/*  67:    */     
/*  68:    */     public boolean value(PsiFile paramPsiFile)
/*  69:    */     {
/*  70: 72 */       return paramPsiFile.getFileType() == this.a;
/*  71:    */     }
/*  72:    */   }
/*  73:    */   
/*  74:    */   private static class PatternCondition
/*  75:    */     implements Condition<PsiFile>
/*  76:    */   {
/*  77:    */     private final PsiFilePattern a;
/*  78:    */     
/*  79:    */     public PatternCondition(PsiFilePattern paramPsiFilePattern)
/*  80:    */     {
/*  81: 80 */       this.a = paramPsiFilePattern;
/*  82:    */     }
/*  83:    */     
/*  84:    */     public boolean value(PsiFile paramPsiFile)
/*  85:    */     {
/*  86: 85 */       return this.a.accepts(paramPsiFile);
/*  87:    */     }
/*  88:    */   }
/*  89:    */   
/*  90:    */   private static class MyFileReference
/*  91:    */     extends FileReference
/*  92:    */   {
/*  93:    */     private final Condition<PsiFile> f;
/*  94:    */     private final Boolean g;
/*  95:    */     
/*  96:    */     public MyFileReference(FileReference paramFileReference, Condition<PsiFile> paramCondition, @Nullable Boolean paramBoolean)
/*  97:    */     {
/*  98: 94 */       super(paramFileReference.getRangeInElement(), paramFileReference.getIndex(), paramFileReference.getCanonicalText());
/*  99: 95 */       this.f = paramCondition;
/* 100: 96 */       this.g = paramBoolean;
/* 101:    */     }
/* 102:    */     
/* 103:    */     public boolean isSoft()
/* 104:    */     {
/* 105:101 */       return this.g == null ? super.isSoft() : this.g.booleanValue();
/* 106:    */     }
/* 107:    */     
/* 108:    */     public PsiFileSystemItem resolve()
/* 109:    */     {
/* 110:106 */       PsiFileSystemItem localPsiFileSystemItem = super.resolve();
/* 111:107 */       if (((localPsiFileSystemItem instanceof PsiFile)) && 
/* 112:108 */         (!this.f.value((PsiFile)localPsiFileSystemItem))) {
/* 113:109 */         return null;
/* 114:    */       }
/* 115:112 */       return localPsiFileSystemItem;
/* 116:    */     }
/* 117:    */     
/* 118:    */     protected ResolveResult[] innerResolve()
/* 119:    */     {
/* 120:117 */       ResolveResult[] arrayOfResolveResult = super.innerResolve();
/* 121:118 */       (ResolveResult[])ContainerUtil.findAll(arrayOfResolveResult, new Condition()
/* 122:    */       {
/* 123:    */         public boolean value(ResolveResult paramAnonymousResolveResult)
/* 124:    */         {
/* 125:121 */           PsiElement localPsiElement = paramAnonymousResolveResult.getElement();
/* 126:122 */           return FileReferenceUtil.MyFileReference.a(localPsiElement, FileReferenceUtil.MyFileReference.this.f);
/* 127:    */         }
/* 128:122 */       }).toArray(ResolveResult.EMPTY_ARRAY);
/* 129:    */     }
/* 130:    */     
/* 131:    */     @NotNull
/* 132:    */     public Object[] getVariants()
/* 133:    */     {
/* 134:130 */       Object[] arrayOfObject = super.getVariants(); Object[] 
/* 135:131 */         tmp22_17 = ContainerUtil.findAll(arrayOfObject, new Condition()).toArray();
/* 136:131 */       if (tmp22_17 == null) {
/* 137:131 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/references/FileReferenceUtil$MyFileReference", "getVariants" }));
/* 138:    */       }
/* 139:131 */       return tmp22_17;
/* 140:    */     }
/* 141:    */     
/* 142:    */     private static boolean a(Object paramObject, Condition<PsiFile> paramCondition)
/* 143:    */     {
/* 144:143 */       return (!(paramObject instanceof PsiFileSystemItem)) || (((PsiFileSystemItem)paramObject).isDirectory()) || (((paramObject instanceof PsiFile)) && (paramCondition.value((PsiFile)paramObject)));
/* 145:    */     }
/* 146:    */   }
/* 147:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.references.FileReferenceUtil

 * JD-Core Version:    0.7.0.1

 */